package com.bjpowernode.controller;

import com.bjpowernode.utils.FileUtils;
import jakarta.annotation.Resource;
import org.springframework.ai.openai.OpenAiAudioSpeechClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;

// 文本转语音
@RestController
public class TTSController {

    @Resource
    private OpenAiAudioSpeechClient openAiAudioSpeechClient;

    @RequestMapping("/ai/tts")
    public Object tts() {
        // String text = "没有编制教师岗还有吸引力吗？”日前，网传厦门市翔安区骨干教师招聘因多岗位取消编制导致无人报考，只能取消招聘计划。厦门市翔安区教育局发布的一则《关于公开招聘骨干教师（2024年4月）取消及减少部分岗位的通告》，引发不少讨论";
        String text = "Spring AI is an application framework for AI engineering. Its goal is to apply to the AI domain Spring ecosystem design principles such as portability and modular design and promote using POJOs as the building blocks of an application to the AI domain.";
        byte[] bytes = openAiAudioSpeechClient.call(text);

        FileUtils.save2File("D:\\temp\\SpringAI\\test.mp3", bytes);

        return "ok";
    }

}
